/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.business.data;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

/**
 *
 * @author alabuschagne
 */
@Entity
public class UserCompanyGroup implements Serializable
{

    private static final long serialVersionUID = 1L;
    private Long id;
    private UserLoginDetails user;
    private Company company;
    private UserGroups userGroup;

    public UserCompanyGroup()
    {
        super();
    }
    public UserCompanyGroup(UserLoginDetails user, Company company, UserGroups userGroup)
    {
        super();
        this.user = user;
        this.company = company;
        this.userGroup = userGroup;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserCompanyGroup))
        {
            return false;
        }
        UserCompanyGroup other = (UserCompanyGroup) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "za.co.pas.business.data.UserCompanyGroup[id=" + id + "]";
    }

    /**
     * @return the user
     */
    @OneToOne
    public UserLoginDetails getUser()
    {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(UserLoginDetails user)
    {
        this.user = user;
    }

    /**
     * @return the company
     */
    @OneToOne
    public Company getCompany()
    {
        return company;
    }

    /**
     * @param company the company to set
     */
    public void setCompany(Company company)
    {
        this.company = company;
    }

    /**
     * @return the userGroup
     */
    @OneToOne
    public UserGroups getUserGroup()
    {
        return userGroup;
    }

    /**
     * @param userGroup the userGroup to set
     */
    public void setUserGroup(UserGroups userGroup)
    {
        this.userGroup = userGroup;
    }

    public boolean check(UserCompanyGroup userGroup)
    {
        return true;//:(
    }

    public String logPrint(int level)
    {
        StringBuilder tab = new StringBuilder();
        for(int i = 0; i < level; i++)
        {
            tab.append("\t");
        }
        StringBuilder sb = new StringBuilder(tab.toString());
        sb.append("USERCOMPANYGROUP\n");
        sb.append(tab.toString());
        sb.append("ID: \t");
        sb.append(id);
        sb.append("\n");
        sb.append(tab.toString());
        sb.append("User: \t");
        sb.append(user.getUserName());
        sb.append("\n");
        sb.append(tab.toString());
        sb.append("Company: \t");
        sb.append(company.getName());
        sb.append("\n");
        sb.append(tab.toString());
        sb.append("UserGroup: \t");
        sb.append(userGroup.toString());
        return sb.toString();
    }
}
